Fog = class('Fog')


function Fog:initialize(x, y)



	self.x = x or 0
	self.y = y or 0
	self.w = tile_size*scale
	self.h = tile_size*scale
	self.layout = layout
	self.seen = false

	table.insert(fog, self)







end

function Fog:see()
		
	if not SceneCompletelyLit then
		-- if the light beam or the player collide with the fog, it
		-- turns to visible space
		if p_light_beam_collide(dOX+(self.x-map_x)*tile_size*scale,
			dOY+(self.y-map_y)*tile_size*scale) then

			self.seen = true

		end

		if pX == self.x and pY == self.y then

			self.seen = true

		end



		local ax = math.abs(pX-self.x)
		local ay = math.abs(pY-self.y)
		local ax2 = pX-self.x
		local ay2 = pY-self.y
		local light_dist = 2

		if player.light then	-- aura of light increases when flashlight is on

			light_dist = 3

		end


		if ax <= light_dist and  ay <= light_dist then

			if not (ax2 == light_dist and ay2 == light_dist)
				and not (ax2 == -light_dist and ay2 == light_dist)
				and not (ax2 == light_dist and ay2 == -light_dist)
				and not (ax2 == -light_dist and ay2 == -light_dist) then
				-- tiles within light_dist are lit up
				self.seen = true
				self.dim = false
			end

		elseif self.seen then

			self.dim = true

		end
	end
end


function Fog:multi(layout)

	-- throw a shitload of fog out there

	for y = 1, #layout do

		for x = 1, #layout[y] do

			local fog = Fog:new(x, y)

		end

	end

end

function Fog:draw()


	-- draw your foggies

	for i = 1, #fog do



		fog[i]:see()

		if not fog[i].seen then
			love.graphics.setColor(0, 0, 0, 240)
			love.graphics.rectangle("fill",
				dOX+((fog[i].x-map_x)*(tile_size*scale)),
				dOY+((fog[i].y-map_y)*(tile_size*scale)),
				fog[i].w, fog[i].h)

		elseif fog[i].dim then

			love.graphics.setColor(0,0,0,128)
			love.graphics.rectangle("fill",
				dOX+((fog[i].x-map_x)*(tile_size*scale)),
				dOY+((fog[i].y-map_y)*(tile_size*scale)),
				fog[i].w, fog[i].h)


		end

	end

	love.graphics.setColor(255,255,255)


end

function Fog:set_seen_all( bSeen )
	if bSeen then
		for i = 1, #fog do
			fog[i].seen = bSeen
		end
	else
		print("FOG set fog all error bSeen not defined")
	end
end

